package com.rop.system.controller;

import com.rop.model.vo.LoginVo;
import com.rop.result.Result;
import com.rop.system.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Title: IndexController
 * @Author Rop
 * @Date 2023/4/9 10:11
 * @description: 用户登录接口
 */

@Api(tags = "用户登录接口")
@RestController
@RequestMapping("admin/system/index")
public class IndexController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * login
     *
     * @return 登陆成功信息
     * {"code":20000,"data":{"token":"admin-token"}}
     */
    @ApiOperation("登录")
    @PostMapping("login")
    public Result<Object> login(@RequestBody LoginVo loginVo) {
        String login = sysUserService.login(loginVo);
        Map<String, Object> map = new HashMap<>();
        map.put("token", login);
        return Result.ok(map);
    }

    /**
     * 用户详情
     * @return 用户详情
     * {
     *     "code": 20000,
     *     "data": {
     *         "roles": [
     *             "admin"
     *         ],
     *         "introduction": "I am a super administrator",
     *         "avatar": "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
     *         "name": "Super Admin"
     *     }
     * }
     */
    @ApiOperation("用户详情")
    @GetMapping("info")
    public Result<Object> info(HttpServletRequest request) {
        Map<String,Object> map = sysUserService.info(request);
        return Result.ok(map);
    }

    /**
     * 注销
     * @return 注销结果
     */
    @ApiOperation("注销用户")
    @PostMapping("logout")
    public Result<Void> logout() {
        return Result.ok();
    }
}
